<script lang="ts" setup>
import type { VbenFormProps } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';

import { Button, Modal } from 'ant-design-vue';

import { useVbenVxeGrid } from '#/adapter/vxe-table';

import { useRouter } from 'vue-router';

const router = useRouter();

interface RowType {
  id: string;
  price: string;
  staffName: string;
  staffNo: string;
  type: string;
  content: string;
  status: string;
}

const formOptions: VbenFormProps = {
  // 默认展开
  collapsed: false,
  schema: [
    {
      component: 'Input',
      defaultValue: '',
      fieldName: 'category',
      label: 'ID',
    },
    {
      component: 'Input',
      fieldName: 'productName',
      label: '日期',
    },
    {
      component: 'Input',
      fieldName: 'productName',
      label: '部门',
    },
    {
      component: 'Input',
      fieldName: 'productName',
      label: '员工姓名',
    },
  ],
  // 控制表单是否显示折叠按钮
  showCollapseButton: true,
  // 按下回车时是否提交表单
  submitOnEnter: false,
};

const gridOptions: VxeGridProps<RowType> = {
  checkboxConfig: {
    highlight: true,
    labelField: 'name',
  },
  columns: [
    { field: 'id', title: '员工ID' },
    { field: 'staffName', title: '员工姓名' },
    { field: 'staffNo', title: '工号' },
    { field: 'type', title: '部门' },
    { field: 'content', title: '回答内容' },
    { field: 'status', title: '统计数据' },
  ],
  height: 'auto',
  keepSource: false,
  pagerConfig: {},
  data: [
    {
      id: '1',
      staffName: '张三',
      staffNo: '001',
      type: '技术部',
      content: 'A',
      status: '20%',
    },
    {
      id: '2',
      staffNo: '002',
      staffName: 'linda',
      type: '产品部',
      content: 'B',
      status: '50%',
    },
  ],
};

const [Grid] = useVbenVxeGrid({ formOptions, gridOptions });

function routerPush(name: string, id: number) {
  // 这里就是路由跳转，也可以用path
  router.push({ name: name, params: { id } });
}

function handleDelete(id: number) {
  Modal.confirm({
    title: '确认删除',
    content: '是否确认删除该活动？',
    onOk() {
      console.log('ok');
    },
    onCancel() {
      console.log('cancel');
    },
  });
}
</script>

<template>
  <Page auto-content-height>
    <Grid>
      <template #toolbar-tools>
        <Button class="mr-2" type="primary">导出</Button>
      </template>
    </Grid>
  </Page>
</template>
